package com.ruoyi.project.WebMoudle.belongBank.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.belongBank.domain.BelongBank;
import com.ruoyi.project.WebMoudle.belongBank.service.IBelongBankService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 绑定银行卡Controller
 * 
 * @author ruoyi
 * @date 2020-07-18
 */
@Controller
@RequestMapping("/belongBank/belongBank")
public class BelongBankController extends BaseController
{
    private String prefix = "belongBank/belongBank";

    @Autowired
    private IBelongBankService belongBankService;

    @RequiresPermissions("belongBank:belongBank:view")
    @GetMapping()
    public String belongBank()
    {
        return prefix + "/belongBank";
    }

    /**
     * 查询绑定银行卡列表
     */
    @RequiresPermissions("belongBank:belongBank:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BelongBank belongBank)
    {
        startPage();
        List<BelongBank> list = belongBankService.selectBelongBankList(belongBank);
        return getDataTable(list);
    }

    /**
     * 导出绑定银行卡列表
     */
    @RequiresPermissions("belongBank:belongBank:export")
    @Log(title = "绑定银行卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BelongBank belongBank)
    {
        List<BelongBank> list = belongBankService.selectBelongBankList(belongBank);
        ExcelUtil<BelongBank> util = new ExcelUtil<BelongBank>(BelongBank.class);
        return util.exportExcel(list, "belongBank");
    }

    /**
     * 新增绑定银行卡
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存绑定银行卡
     */
    @RequiresPermissions("belongBank:belongBank:add")
    @Log(title = "绑定银行卡", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BelongBank belongBank)
    {
        return toAjax(belongBankService.insertBelongBank(belongBank));
    }

    /**
     * 修改绑定银行卡
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BelongBank belongBank = belongBankService.selectBelongBankById(id);
        mmap.put("belongBank", belongBank);
        return prefix + "/edit";
    }

    /**
     * 修改保存绑定银行卡
     */
    @RequiresPermissions("belongBank:belongBank:edit")
    @Log(title = "绑定银行卡", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BelongBank belongBank)
    {
        return toAjax(belongBankService.updateBelongBank(belongBank));
    }

    /**
     * 删除绑定银行卡
     */
    @RequiresPermissions("belongBank:belongBank:remove")
    @Log(title = "绑定银行卡", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(belongBankService.deleteBelongBankByIds(ids));
    }
}
